package com.auctionhaus

class Customer {
	//C1
	String emailAddress
	String password
	Date date
    boolean adminRole

    transient loginName = ""

	static hasMany = [bid:Bid, listings:Listing]
    static mappedBy = [listings:'seller', bid: 'buyer']
	static transients = ['currentCustomerList', 'isCustomerLoggedIn', 'isAdmin']

    static constraints = {

	    // C-3
	    emailAddress(email:true, unique:true, blank:false)
	    // C-4
	    password(blank: false, nullable: false, size:6..8)
        loginName(nullable: true)

        }

    static mapping = {
        cache: true
        listings updateable: false
    }

    String getLoginName() {
        if (emailAddress)
            emailAddress.split('@')[0]
        else
            ""
    }


}
